package com.yjz.jvm.juc.join;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class join_learn {

  private static Thread t1 = new Thread(() -> {
    try {
      Thread.sleep(3000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    log.info(Thread.currentThread().getName() + "开始执行");
  }, "线程1");
  private static Thread t2 = new Thread(() -> {
    log.info(Thread.currentThread().getName() + "开始执行");
  }, "线程2");

  public static void main(String[] args) throws InterruptedException {
    //某个线程调用join方法，则其他线程会等待该线程执行完再执行
    //join 可以让线程达到排队执行的效果
    log.info(Thread.currentThread().getName() + "开始执行");
    t1.start();
    //	t1.join(); //主线程调用t1线程的join方法，则主线程进入waiting状态，直到t1执行完成
    t2.start();
    //	t2.join();
    log.info(Thread.currentThread().getName() + "结束执行");
    //t1 t2 main 这三个线程依次执行
  }

}
